home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / BM132A.LZH / bm_132a / levelmap.s < prev    next >
Encoding:
Text File  |  1995-11-26  |  7.3 KB  |  349 lines

  1. *=======================================================*
  2. *    LevelMap: latest update 21/11/95        *
  3. *=======================================================*
  4. *    Display the 2d map.                *
  5. *=======================================================*
  6. *     >    Written by Laurent Sallafranque         *
  7. *=======================================================*
  8. *    Things to do :                    *
  9. *=======================================================*
  10. *     >                            *
  11. *     >                            *
  12. *=======================================================*
  13.  
  14. *-------------------------------------------------------*
  15. *    This function displays the level's map when    *
  16. *    the player press the TAB key.            *
  17. *-------------------------------------------------------*
  18. display_map:
  19.     tst.b    map_enabled
  20.     bne.s    .go
  21.     rts
  22. .go:    move.l    Line_Array,a0
  23.     move.l    Vertex_Array,a1
  24.     move.l    #32760,d4            ; x map min
  25.     move.l    #-32760,d5            ; x map max
  26.     move.l    #32760,d6            ; y map min
  27.     move.l    #-32760,d7            ; y map max
  28.     move.w    NumLines,d0    
  29.     subq.w    #1,d0
  30.  
  31. *-------------------------------------------------------*
  32. *    Search Xmap min, Xmap max, Ymap min & Ymap max    *
  33. *-------------------------------------------------------*
  34. .for_lines:
  35.     moveq    #0,d1
  36.     moveq    #0,d2
  37.     movem.w    (a0),d1-d2            ; linedef from d1 to d2
  38.     move.w    Vertex_y(a1,d2.l*4),d3        ; y2
  39.     ext.l    d3
  40.     cmp.l    d3,d6
  41.     ble.s    .test2
  42.     move.l    d3,d6
  43.     bra.s    .test3
  44. .test2:    cmp.l    d3,d7
  45.     bge.s    .test3
  46.     move.l    d3,d7
  47. .test3:    move.w    Vertex_x(a1,d2.l*4),d3        ; x2
  48.     ext.l    d3
  49.     cmp.l    d3,d4
  50.     ble.s    .test4
  51.     move.l    d3,d4
  52.     bra.s    .test5
  53. .test4:    cmp.l    d3,d5
  54.     bge.s    .test5
  55.     move.l    d3,d5
  56. .test5:    move.w    Vertex_y(a1,d1.l*4),d3        ; y1
  57.     ext.l    d3
  58.     cmp.l    d3,d6
  59.     ble.s    .test6
  60.     move.l    d3,d6
  61.     bra.s    .test7
  62. .test6:    cmp.l    d3,d7
  63.     bge.s    .test7
  64.     move.l    d3,d7
  65. .test7:    move.w    Vertex_x(a1,d1.l*4),d3        ; x1
  66.     ext.l    d3
  67.     cmp.l    d3,d4
  68.     ble.s    .test8
  69.     move.l    d3,d4
  70.     bra.s    .next
  71. .test8:    cmp.l    d3,d5
  72.     bge.s    .next
  73.     move.l    d3,d5
  74. .next:    lea    Line_len(a0),a0            ; Next line
  75.     dbf    d0,.for_lines
  76.  
  77. *-------------------------------------------------------*
  78. *    Calculate Dx = Xmap max - Xmap min        *
  79. *              Dy = Ymap max - Ymap min        *
  80. *-------------------------------------------------------*
  81.     sub.l    d4,d5
  82.     sub.l    d6,d7
  83. *-------------------------------------------------------*
  84. *    Calculate Min( width / Dx ; height / Dy )    *
  85. *-------------------------------------------------------*
  86.     move.w    width,d0
  87.     swap    d0
  88.     clr.w    d0
  89.     divu.l    d5,d0
  90.     move.w    height,d1
  91.     swap    d1
  92.     clr.w    d1
  93.     divu.l    d7,d1
  94.     cmp.l    d1,d0
  95.     ble.s    .small
  96.     move.l    d1,d0
  97. .small:    move.l    d4,a2                ; save xmap min
  98.     move.l    d6,a3                ; save ymap min
  99.     move.l    d0,X_Y_map_Corr            ; save smaller_one
  100.  
  101. *-------------------------------------------------------*
  102. *    Main map display routine            *
  103. *-------------------------------------------------------*
  104.     move.w    NumLines,d0    
  105.     subq.w    #1,d0
  106.     move.l    Line_Array,a0
  107. .for_lines2:
  108.     movem.w    (a0),d1-d3            ; from, to, attributes                
  109.     move.w    #$ffe0,d5            ; wall color is yellow
  110.  
  111.     move.w    d3,d4                ; test if wall is already
  112.     and.w    #$100,d4            ;   on map, also if never
  113.     bne.s    .show_wall            ;   seen before
  114.  
  115.     btst    #7,d3                ; test is wall mustn't be
  116.     bne.s    .next_line            ;   on map
  117.  
  118. .show_wall:
  119.     btst    #0,d3
  120.     beq.s    .not_external_wall
  121.     move.w    #$f800,d5            ; wall color is red            
  122. .not_external_wall:
  123. .display_level:
  124.     move.w    Vertex_y(a1,d2.w*4),d6        ; y2
  125.     ext.l    d6
  126.     sub.l    a3,d6
  127.     mulu.l    X_Y_map_Corr,d6
  128.     swap    d6
  129.     move.w    height,d4
  130.     subq.w    #1,d4
  131.     sub.w    d6,d4
  132.  
  133.     move.w    Vertex_x(a1,d2.w*4),d3        ; x2
  134.     ext.l    d3
  135.     sub.l    a2,d3
  136.     mulu.l    X_Y_map_Corr,d3
  137.     swap    d3
  138.  
  139.     move.w    Vertex_y(a1,d1.w*4),d6        ; y1
  140.     ext.l    d6
  141.     sub.l    a3,d6
  142.     mulu.l    X_Y_map_Corr,d6
  143.     swap    d6
  144.     move.w    height,d2
  145.     subq.w    #1,d2
  146.     sub.w    d6,d2
  147.  
  148.     move.w    Vertex_x(a1,d1.w*4),d1        ; x1
  149.     ext.l    d1
  150.     sub.l    a2,d1
  151.     mulu.l    X_Y_map_Corr,d1
  152.     swap    d1
  153.     bsr    display_line
  154. .next_line:
  155.     lea    14(a0),a0            ; next line
  156.     dbf    d0,.for_lines2
  157.  
  158.     bsr    Display_Player_Position
  159.     rts
  160.  
  161.  
  162. *-------------------------------------------------------*
  163. *    Draw a colored line between 2 points        *
  164. *-------------------------------------------------------*
  165. *        d1 : X1        d2 : Y1            *
  166. *        d3 : X2        d4 : Y2            *
  167. *        d5 : color of the line            *
  168. *-------------------------------------------------------*
  169. display_line:
  170.     movem.l    d0-d7/a0-a2,-(sp)
  171.     move.w    d5,a2
  172.     move.l    screen,a0
  173.     move.w    scrwidth,d0            ; 2 * width screen
  174.     add.w    d0,d0
  175.  
  176.     move.w    d4,d6                ; d6 = Y1-Y2 = dY
  177.     sub.w    d2,d6
  178.     beq    .h_line
  179.     
  180.     move.w    d3,d5
  181.     sub.w    d1,d5                ; d5 = X2-X1 = dX
  182.     beq    .v_line    
  183.     bmi.s    .line1                ; dX < 0 ?
  184.     
  185.     move.w    d2,d7
  186.     add.w    d1,d1                ; X2 > X1
  187.     move.w    d1,a1
  188.     bra.w    .n_line
  189.  
  190. .line1:    neg.w    d5                ; X2 < X1
  191.     neg.w    d6
  192.     move.w    d4,d7
  193.     add.w    d3,d3
  194.     move.w    d3,a1     
  195.  
  196. .n_line:
  197.     tst.w    d6
  198.     bpl.s    .n_line0
  199.     neg.w    d6
  200.     neg.w    d0
  201.  
  202. .n_line0:
  203.     move.w    scrwidth,d1
  204.     add.w    d1,d1
  205.     cmp.w    d6,d5
  206.     bmi.s    .n_line2
  207.     
  208.  
  209. .n_line1:                    ; dX > dY
  210.     add.w    d6,d6
  211.     move.w    d6,d3
  212.     sub.w    d5,d6
  213.     move.w    d6,d4
  214.     sub.w    d5,d4
  215.  
  216.     mulu    d1,d7
  217.     add.l    a1,d7
  218.     lea    (a0,d7.l),a0            ; logscreen adress
  219.     move.w    a2,d2                ; pixel color
  220.  
  221. .lin1_lp2
  222.     tst.w    d6
  223.     bmi.s    .lin1_no_y
  224.     add.w    d4,d6
  225.     move.w    d2,(a0)+            ; display pixel
  226.     add.w    d0,a0
  227.     dbf    d5,.lin1_lp2
  228.     movem.l    (sp)+,d0-d7/a0-a2
  229.     rts
  230. .lin1_no_y    
  231.     add.w    d3,d6        
  232.     move.w    d2,(a0)+            ; display pixel
  233.     dbf    d5,.lin1_lp2
  234.     movem.l    (sp)+,d0-d7/a0-a2
  235.     rts
  236.     
  237. .n_line2:                    ; dX < dY
  238.     exg    d6,d5
  239.     add.w    d6,d6
  240.     move.w    d6,d3
  241.     sub.w    d5,d6
  242.     move.w    d6,d4
  243.     sub.w    d5,d4
  244.  
  245.     mulu    d1,d7
  246.     add.l    a1,d7
  247.     lea    (a0,d7.l),a0
  248.     move.w    a2,d2                ; pixel color
  249.  
  250. .lin2_lp:
  251.     tst.w    d6
  252.     bmi.s    .lin2_no_x
  253.      add.w    d4,d6
  254.     move.w    d2,(a0)+            ; display pixel
  255.     add.w    d0,a0 
  256.     dbf    d5,.lin2_lp
  257.     movem.l    (sp)+,d0-d7/a0-a2
  258.     rts
  259. .lin2_no_x:
  260.     add.w    d3,d6
  261.     move.w    d2,(a0)                ; display pixel
  262.     add.w    d0,a0 
  263.     dbf    d5,.lin2_lp
  264.     movem.l    (sp)+,d0-d7/a0-a2
  265.     rts
  266.     
  267. .h_line:                    ; Y1 = Y2
  268.     cmp.w    d1,d3
  269.     bge.s    .hline1    
  270.     exg    d1,d3
  271. .hline1:
  272.     sub.w    d1,d3
  273.     subq.w    #1,d3
  274.     ble.s    .end_h
  275.     move.w    scrwidth,d5
  276.     add.w    d5,d5
  277.     mulu    d5,d2
  278.     add.w    d1,d1
  279.     add.w    d1,d2
  280.     lea    (a0,d2.l),a0            ; screen adress
  281.     move.w    a2,d2                ; pixel color
  282. .for_h:    move.w    d2,(a0)+
  283.     dbf    d3,.for_h
  284. .end_h:    movem.l    (sp)+,d0-d7/a0-a2
  285.     rts
  286.     
  287. .v_line:                    ; X1 = X2
  288.     tst.w    d6
  289.     bgt.s    .lvert2
  290.     exg    d2,d4    
  291.     neg.w    d6
  292. .lvert2:
  293.     subq.w    #1,d6
  294.     ble.s    .end_v
  295.     add.w    d1,d1
  296.     move.w    scrwidth,d5
  297.     add.w    d5,d5
  298.     mulu    d5,d2
  299.     add.w    d1,d2
  300.     lea    (a0,d2.l),a0            ; screen adress
  301.     move.w    a2,d2                ; pixel color
  302. .for_v:    move.w    d2,(a0)
  303.     lea    (a0,d5.w),a0
  304.     dbf    d6,.for_v
  305. .end_v:    movem.l    (sp)+,d0-d7/a0-a2
  306.     rts
  307.  
  308. *-------------------------------------------------------*
  309. *    Display player position on the map        *
  310. *-------------------------------------------------------*
  311. Display_Player_Position:
  312.     move.w    Px,d3                ; Player's x position
  313.     ext.l    d3
  314.     sub.l    a2,d3
  315.     mulu.l    X_Y_map_Corr,d3
  316.     swap    d3
  317.     move.w    Py,d6                ; Player's y position
  318.     ext.l    d6
  319.     sub.l    a3,d6
  320.     mulu.l    X_Y_map_Corr,d6
  321.     swap    d6
  322.     move.w    height,d4
  323.     subq.w    #1,d4
  324.     sub.w    d6,d4
  325.     move.l    SinPangle,d2            ; y player vector view
  326.     move.w    #14,d6
  327.     asr.l    d6,d2    
  328.     add.w    d4,d2
  329.     move.l    CosPangle,d1            ; x player vector view
  330.     asr.l    d6,d1    
  331.     add.w    d3,d1
  332.     move.w    #$ffff,d5            ; display in white
  333.     bsr    display_line
  334.     rts
  335.  
  336. *-------------------------------------------------------*
  337.             bss
  338. *-------------------------------------------------------*
  339.  
  340. X_Y_map_Corr:        ds.l    1
  341. map_enabled:        ds.b    1
  342.             even
  343.  
  344. *-------------------------------------------------------*
  345.             text
  346. *-------------------------------------------------------*
  347.  
  348.         
  349.